﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace EFong.Contract
{
    [DataContract]
    public class ServiceResult<T>
    {
        public ServiceResult()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }

        [DataMember]
        public bool IsSuccess
        {
            get;
            set;
        }

        [DataMember]
        public int FailType
        {
            get;
            set;
        }

        [DataMember]
        public string FailMessage
        {
            get;
            set;
        }

        [DataMember]
        public T ReturnValue
        {
            get;
            set;
        }

        public List<FailValue> FailValues
        {
            get;
            set;
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(string.Format("IsSuccess:{0}", IsSuccess));
            if (IsSuccess)
            {
                sb.AppendLine(string.Format("Return:{0}", ReturnValue));
            }
            else
            {
                sb.AppendLine(string.Format("Type:{0}      Message:{1}", FailType, FailMessage));
                foreach (var failValue in FailValues)
                {
                    sb.AppendLine(string.Format("{0}:{1}", failValue.Name, failValue.Value));
                }
            }

            return sb.ToString();
        }
    }


    public class ServiceResult : ServiceResult<object>
    {
    }
}
